package com.cookor.poi.modules.phy.service;

import com.cookor.poi.common.persistence.DataEntity;
import com.cookor.poi.common.persistence.Page;
import com.cookor.poi.common.service.CrudService;
import com.cookor.poi.common.utils.JedisUtils;
import com.cookor.poi.modules.phy.dao.TArticleTypeDao;
import com.cookor.poi.modules.phy.entity.TArticle;
import com.cookor.poi.modules.phy.entity.TArticleType;
import java.util.Iterator;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional(readOnly = true)
public class TArticleTypeService extends CrudService<TArticleTypeDao, TArticleType> {
  @Autowired
  @Lazy
  private TArticleService tArticleService;
  
  public TArticleType get(String id) {
    return (TArticleType)super.get(id);
  }
  
  public List<TArticleType> findList(TArticleType tArticleType) {
    return super.findList( tArticleType);
  }
  
  public Page<TArticleType> findPage(Page<TArticleType> page, TArticleType tArticleType) {
    return super.findPage(page,  tArticleType);
  }
  
  @Transactional(readOnly = false)
  public void save(TArticleType tArticleType) {
    super.save( tArticleType);
    tArticleType = new TArticleType();
    tArticleType.setTenantId(Integer.valueOf(5));
    tArticleType.setDelFlag("0");
    List<TArticleType> typeList = findList(tArticleType);
    Iterator<TArticleType> it = typeList.iterator();
    while (it.hasNext()) {
      TArticleType type = it.next();
      if (type.getTypeName().equals("系统公告")) {
        it.remove();
        continue;
      } 
      TArticle tArticle = new TArticle();
      tArticle.setTenantId(Integer.valueOf(5));
      tArticle.setType(Integer.valueOf(type.getId()));
      tArticle.setDelFlag("0");
      type.setArticleList(this.tArticleService.findPage(new Page(1, 3), tArticle).getList());
    } 
    JedisUtils.setObject("articleList", typeList, 1800);
  }
  
  @Transactional(readOnly = false)
  public void delete(TArticleType tArticleType) {
    super.delete( tArticleType);
  }
}
